{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from __future__ import print_function\n",
    "%matplotlib inline\n",
    "import mdtraj as md"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Lets load up the trajectory that we simulated in a previous example"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "traj = md.load('ala2.h5')\n",
    "atoms, bonds = traj.topology.to_dataframe()\n",
    "atoms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Because alanine dipeptide is a little nonstandard in the sense that it's basically dominated by the ACE and NME capping residues, we need to find the indicies of the atoms involved in the phi and psi angles somewhat manually. For standard cases, see `compute_phi()` and `compute_psi()` for easier solutions that don't require you to manually find the indices of each dihedral angle.\n",
    "\n",
    "In this case, we're just specifying the four atoms that together parameterize the phi and psi dihedral angles."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "psi_indices, phi_indices = [6, 8, 14, 16], [4, 6, 8, 14]\n",
    "angles = md.compute_dihedrals(traj, [phi_indices, psi_indices])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Lets plot our dihedral angles in a scatter plot using matplotlib. What conformational states of Alanine dipeptide did we sample?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "from pylab import *\n",
    "from math import pi\n",
    "\n",
    "figure()\n",
    "title('Dihedral Map: Alanine dipeptide')\n",
    "scatter(angles[:, 0], angles[:, 1], marker='x', c=traj.time)\n",
    "cbar = colorbar()\n",
    "cbar.set_label('Time [ps]')\n",
    "xlabel(r'$\\Phi$ Angle [radians]')\n",
    "xlim(-pi, pi)\n",
    "ylabel(r'$\\Psi$ Angle [radians]')\n",
    "ylim(-pi, pi)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
